/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commons;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Adrian
 */
public class ZapomnianeHasloManager {

    private String pass1, pass2, login,id;

    public String zmien() {
        try {
            if (pass1.equals(pass2)) {
                Connection conn = (Connection) DbConnection.getConnection();
                PreparedStatement ps = (PreparedStatement) conn.prepareStatement("SELECT login,ident_biblioteczny FROM dane_logowania where login=?");
                ps.setString(1, login);
                ResultSet rs = ps.executeQuery();
                if (rs.next()) {
                    if (login.equals(rs.getString("login")) && id.equals(rs.getString("ident_biblioteczny"))) {
                        ps = (PreparedStatement) conn.prepareStatement("UPDATE `biblioteka`.`dane_logowania` SET `haslo` = ? WHERE login = ?");
                        ps.setString(1, this.pass1);
                        ps.setString(2, this.login);
                        ps.executeUpdate();
                        return "zaktualizowano";
                    }else{
                        return "blad";
                    }
                } else {
                    return "blad";
                }
            } else {
                return "blad";
            }
        } catch (SQLException ex) {
            Logger.getLogger(ZapomnianeHasloManager.class.getName()).log(Level.SEVERE, null, ex);
            return "error";
        }
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPass1() {
        return pass1;
    }

    public void setPass1(String pass1) {
        this.pass1 = pass1;
    }

    public String getPass2() {
        return pass2;
    }

    public void setPass2(String pass2) {
        this.pass2 = pass2;
    }
}
